home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / pbClock / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  3.5 KB  |  131 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        IdleTasks.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This function is called when a null event is received.  Do appropriate tasks
  20. ** for null event situations, such as handling balloon help for window. */
  21.  
  22.  
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27.  
  28. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  29. #include "App.defs.h"        /* Get various application definitions.            */
  30. #include "App.protos.h"        /* Get the prototypes for application.            */
  31.  
  32. #ifndef __RESOURCES__
  33. #include <Resources.h>
  34. #endif
  35.  
  36. #ifndef __SOUND__
  37. #include <Sound.h>
  38. #endif
  39.  
  40.  
  41.  
  42. /*****************************************************************************/
  43. /*****************************************************************************/
  44.  
  45.  
  46.  
  47. #pragma segment Main
  48. void    DoIdleTasks(EventRecord *event)
  49. {
  50. #ifndef __MWERKS__
  51. #pragma unused (event)
  52. #endif
  53.  
  54.     EventRecord        evt;
  55.     WindowPtr        window;
  56.     FileRecHndl        frHndl;
  57.     TreeObjHndl        root;
  58.     ControlHandle    ctl;
  59.     short            lr, rs;
  60.     long            timer, tick, t1, t2;
  61.     Handle            snd;
  62.     KeyMap            kk;
  63.     short            mm;
  64.  
  65.     if (TSMTEAvailable()) TSMEvent(event);
  66.  
  67.     GetKeys(kk);
  68.     mm  = (kk[1] & 0x8000) ? (cmdKey    ) : 0;
  69.     mm |= (kk[1] & 0x0004) ? (optionKey ) : 0;
  70.     mm |= (kk[1] & 0x0008) ? (controlKey) : 0;
  71.     mm |= (kk[1] & 0x0001) ? (shiftKey  ) : 0;
  72.     evt.what      = nullEvent;        /* Make valid null event, with modifiers. */
  73.     evt.modifiers = mm;
  74.  
  75.     IsCtlEvent(nil, &evt, nil, nil);
  76.  
  77.     /* •••• All of the code below here was added for pbClock. */
  78.  
  79.     for (window = nil; ((window = GetNextWindow(window, 'pbCk')) != nil);) {
  80.         if (!ClocksPaused(window)) {
  81.             frHndl = (FileRecHndl)GetWRefCon(window);
  82.             root   = (*frHndl)->d.doc.root;
  83.             timer  = (*frHndl)->d.doc.timer;
  84.             if (!timer) {
  85.                 (*frHndl)->d.doc.timer = TickCount();
  86.                 continue;
  87.             }
  88.             tick = ((*frHndl)->d.doc.timer = TickCount()) - timer;
  89.             if (tick < 1) continue;
  90.             rs = mDerefRoot(root)->rightStart;
  91.             if (rs > -1) {
  92.                 if (mDerefRoot(root)->timeRemaining[0]) {
  93.                     if (mDerefRoot(root)->timeRemaining[1]) {
  94.                         lr  = mDerefRoot(root)->numMoves[0];
  95.                         lr += mDerefRoot(root)->numMoves[1];
  96.                         lr += rs;
  97.                         lr &= 0x01;
  98.                         t1  = mDerefRoot(root)->timeRemaining[lr];
  99.                         t2  = t1 - tick;
  100.                         if (t2 < 60) t2 = 0;
  101.                         mDerefRoot(root)->timeRemaining[lr] = t2;
  102.                         if ((t1 / 60) != (t2 / 60)) {
  103.                             DrawClock(frHndl, lr);
  104.                             PostEvent(nullEvent, 0L);    /* Don't let PB100 rest. */
  105.                         }
  106.                         if (!t2) {
  107.                             snd = GetResource('snd ', 500);
  108.                             if (snd) SndPlay(nil, snd, false);
  109.                             CNum2Ctl(window, kTabButton, &ctl);
  110.                             UseControlStyle(ctl);
  111.                             HiliteControl(ctl, 255);
  112.                             UseControlStyle(nil);
  113.                             CNum2Ctl(window, kReturnButton, &ctl);
  114.                             UseControlStyle(ctl);
  115.                             HiliteControl(ctl, 255);
  116.                             UseControlStyle(nil);
  117.                             CNum2Ctl(window, kPauseClocks, &ctl);
  118.                             UseControlStyle(ctl);
  119.                             HiliteControl(ctl, 255);
  120.                             UseControlStyle(nil);
  121.                         }
  122.                     }
  123.                 }
  124.             }
  125.         }
  126.     }
  127. }
  128.  
  129.  
  130.  
  131.